'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    if(this.ctx.session.user){
      await ctx.render("index")
    }else{      
      this.ctx.redirect("/login")
    }
  }
  async login(){
    await this.ctx.render("login")
  }

  async doLogin(){
    let name = this.ctx.request.body.userName;
    let pass = this.ctx.request.body.passWord;
    if(name == "admin" && pass == 123456){
      this.ctx.session.user = name;
      this.ctx.redirect("/")
    }else{
      this.ctx.redirect("/login")
    }
  }

  async logout(){
    this.ctx.session.user = "";
    this.ctx.redirect("/login")
  }
}


module.exports = HomeController;
